package de.ars.client.items.animators;

import de.ars.client.animator.Animator;
import de.ars.client.animator.IAnimationEventListener;
import de.ars.client.animator.Point;
import de.ars.client.paintSystems.ClassicLayout;

public class OverViewItemAnimator extends Animator
{
    public static final float STANDARD_ANIMATION_SPEED = 1.5f;
    public static final float STANDARD_SCROLL_SPEED = 10.0f;
    public static final float STANDARD_GROW_SHRINK_SPEED = 2.3f;
    public static final int POINT_WINDOW_POS = 0;
    public static final int POINT_WINDOW_SIZE = 1;
    public static final int POINT_PORTRAIT_POS = 2;
    public static final int POINT_TEXT_POS = 3;
    
    private ClassicLayout layout;
    
    public OverViewItemAnimator( IAnimationEventListener listener )
    {
        super( listener );
    }
    
    public void growToDetail()
    {
        startAnimationTo( POINT_WINDOW_SIZE, layout.getDetailSize(),STANDARD_GROW_SHRINK_SPEED );
        startAnimationTo( POINT_WINDOW_POS, layout.getDetailPos(),STANDARD_GROW_SHRINK_SPEED );
        startAnimationTo( POINT_TEXT_POS, layout.getDetailTextPos(),STANDARD_GROW_SHRINK_SPEED );
        startAnimationTo( POINT_PORTRAIT_POS, layout.getDetailPortraitPos(),STANDARD_GROW_SHRINK_SPEED );
        listener.animationEvent(IAnimationEventListener.ANIMATION_STARTED);
    }
    
    public void shrinkToNormal(int index)
    {
        startAnimationTo( POINT_WINDOW_SIZE, layout.getSize( index ),STANDARD_GROW_SHRINK_SPEED );
        startAnimationTo( POINT_WINDOW_POS, layout.getPos( index ),STANDARD_GROW_SHRINK_SPEED );
        startAnimationTo( POINT_TEXT_POS, layout.getTextPos( index ),STANDARD_GROW_SHRINK_SPEED );
        startAnimationTo( POINT_PORTRAIT_POS, layout.getPortraitPos( index ),STANDARD_GROW_SHRINK_SPEED );
        listener.animationEvent(IAnimationEventListener.ANIMATION_STARTED);
    }

    public void animateTo( int index )
    {
        startAnimationTo( POINT_WINDOW_SIZE, layout.getSize( index ) );
        startAnimationTo( POINT_WINDOW_POS, layout.getPos( index ) );
        startAnimationTo( POINT_TEXT_POS, layout.getTextPos( index ) );
        startAnimationTo( POINT_PORTRAIT_POS, layout.getPortraitPos( index ) );
        listener.animationEvent(IAnimationEventListener.ANIMATION_STARTED);
    }
    
    public void animateScrollUp(int alpha)
    {
        Point tempPoint = this.getPoint( POINT_TEXT_POS );
        tempPoint.setY( tempPoint.getY() +alpha );
        startAnimationTo( POINT_TEXT_POS, tempPoint,STANDARD_SCROLL_SPEED );
        
        tempPoint = this.getPoint( POINT_PORTRAIT_POS );
        tempPoint.setY( tempPoint.getY() +alpha );
        startAnimationTo( POINT_PORTRAIT_POS, tempPoint,STANDARD_SCROLL_SPEED );
        
        listener.animationEvent(IAnimationEventListener.ANIMATION_STARTED);
    }
    
    public void animateScrollDown(int alpha)
    {
        Point tempPoint = this.getPoint( POINT_TEXT_POS );
        tempPoint.setY( tempPoint.getY() -alpha );
        startAnimationTo( POINT_TEXT_POS, tempPoint,STANDARD_SCROLL_SPEED );
        
        tempPoint = this.getPoint( POINT_PORTRAIT_POS );
        tempPoint.setY( tempPoint.getY() -alpha );
        startAnimationTo( POINT_PORTRAIT_POS, tempPoint,STANDARD_SCROLL_SPEED );
        
        listener.animationEvent(IAnimationEventListener.ANIMATION_STARTED);
    }

    public void setLayout(ClassicLayout layout)
    {
        this.layout = layout;
    }
}
